/* GUI CONVERTED from rqbmt.p (converter v1.76) Wed May 22 11:22:58 2002 */
/* rqbmt.p - Buyer Maintenance                                                */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.6.1.3 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION 8.5       LAST MODIFIED: 04/15/97  BY: *J1Q2* Patrick Rowan       */
/* REVISION 8.5       LAST MODIFIED: 10/23/97  BY: *J243* Patrick Rowan       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98  BY: *L007* A. Rahane           */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98  BY: *K1Q4* Alfred Tan          */
/* REVISION: 8.6E     LAST MODIFIED: 05/15/98  BY: *J2GM* Patrick Rowan       */
/* REVISION: 8.6E     LAST MODIFIED: 07/22/98  BY: *J2ST* Niranjan R.         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00  BY: *N08T* Annasaheb Rahane    */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00  BY: *N0KP* Mark Brown          */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.6.1.3 $   BY: Jean Miller        DATE: 05/20/02  ECO: *P05V*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: ADDS/MODS/DELETES buyers.
              Supports the multi-line Purchase Requisition Module of MFG/PRO.

 Notes:
 1) Buyers are stored in the Role Master table (rqr_mstr), with the key value
    of "buyer".
 ============================================================================
!*/

/* DISPLAY TITLE  */
{mfdtitle.i "2+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rqbmt_p_1 "Delete"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqbmt_p_2 "Buyer"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

/* CONSTANTS */
{rqconst.i}

/* VARIABLES */
define variable var_buyer_name like usr_name.
define variable var_del_buyer  like mfc_logical no-undo initial no.

/* LOGICALS  */
define variable del-yn         like mfc_logical no-undo initial no.

/* FRAME A: SELECTION FORM   */


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
rqr_userid            colon 25 label "Buyer"
   var_buyer_name        at 37    no-label
   skip(1)
   var_del_buyer         colon 25 label "Delete"
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* DISPLAY */
view frame a.

mainloop:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


   /* PROMPT-FOR KEYS */
   prompt-for
      rqr_userid
   with frame a
   editing:

      /* FIND NEXT/PREVIOUS RECORD */
      {mfnp05.i rqr_mstr rqr_role "rqr_role = BUYER"
         rqr_userid "input rqr_userid"}

      if recno <> ? then do:
         find usr_mstr where usr_userid = rqr_userid.
         if available (usr_mstr) then
            var_buyer_name = usr_name.
         else
            var_buyer_name = "".

         display
            rqr_userid
            var_buyer_name
         with frame a.

      end.  /* if recno <> ? */

   end.  /* prompt-for */

   /*  ADD/MODIFY/DELETE  */
   find rqr_mstr where
        rqr_role        = BUYER and
        rqr_userid      = input rqr_userid
   exclusive-lock no-error.

   if not available rqr_mstr then do:

      /* APPROVER ID */
      if input rqr_userid = "" or
         not can-find(usr_mstr where
                      usr_mstr.usr_userid = input rqr_userid)
      then do:
         /* User ID does not exist */
         {pxmsg.i &MSGNUM=5605 &ERRORLEVEL=3}
         undo, retry.
      end.

      /* CHECK GENERALIZED CODES */
      if not ({gpcode.v "input rqr_userid" po_buyer}) then do:
         {pxmsg.i &MSGNUM=716 &ERRORLEVEL=3}
         /* VALUE MUST EXIST IN GENERALIZED CODES */
         undo, retry.
      end.

      /* ADD NEW RECORD */
      {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
      create rqr_mstr.
      assign
         rqr_role     = BUYER
         rqr_userid.

      if recid(rqr_mstr) = -1 then .

   end.  /* if not available rqr_mstr */

   find usr_mstr where usr_userid = input rqr_userid.
   if available (usr_mstr) then
      var_buyer_name = usr_name.
   else
      var_buyer_name = "".

   display
      rqr_userid
      var_buyer_name
   with frame a.

   ststatus = stline[2].
   status input ststatus.
   del-yn = no.

   setloop1:
   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


      update
         var_del_buyer
      go-on("F5" "CTRL-D")
      with frame a.

      /*  DELETE  */
      if input var_del_buyer or
         lastkey = keycode("F5") or
         lastkey = keycode("CTRL-D")
      then do:
         del-yn = yes.
         /* Please confirm delete */
         {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
         if del-yn = no then
            undo setloop1.
      end.  /* if lastkey = keycode("F5") */

      if del-yn then do:
         /* OK TO DELETE */
         delete rqr_mstr.
         clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
         del-yn = no.
         var_del_buyer = no.
         next mainloop.
      end.  /* if del-yn */

      /* E-MAIL CHECK ADDRESSES*/
      if can-find(rqf_ctrl where
                  rqf_email_opt <> "1")
      then do:
         if can-find(usr_mstr where
                     usr_userid = rqr_userid and
                     usr_mail_address = "")
         then do:
            /* E-MAIL ADDRESS DOES NOT EXIST */
            {pxmsg.i &MSGNUM=1777 &ERRORLEVEL=2 &MSGARG1=rqr_userid}
         end.  /* if can-find(usr_mstr) */
      end.  /* if can-find(rqf_ctrl) */

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* setloop1  */

end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* mainloop repeat  */

status input.
